package interview.juc;

/**
 * @Author: zhangrongqing
 * @Date: 2019/11/29 14:27
 */
//线程8锁问题
public class Thread8Type {
    public static void main(String[] args) {
        ThreadDemo td = new ThreadDemo();
        new Thread(() -> td.printOne()).start();
        new Thread(() -> td.printTwo()).start();

        //result：Two one
    }
}

class ThreadDemo {
    public static synchronized void printOne() {  //锁的是ThreadDemo.class文件
        try {
            Thread.sleep(2000);
        } catch (InterruptedException e) {
        }
        System.out.println("one");
    }

    public synchronized void printTwo() {   //锁的是this
        System.out.println("Two");
    }
}